package jiaxa.com.jsbridge.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.google.gson.Gson;

import java.util.ArrayList;

import jiaxa.com.jsbridge.Constant;
import jiaxa.com.jsbridge.bean.ApiBean;
import jiaxa.com.jsbridge.bean.Student;
import jiaxa.com.jsbridge.util.GsonUtil;

public class GsonActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //supportRequestWindowFeature(Window.FEATURE_NO_TITLE);  //隐藏标题栏，setContentView之前调用，否则无效。
        //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);   //全屏
//        setContentView(R.layout.activity_news);

        String jsonStr = "{code:'',status:'',errorMsg:'',reqData:{username:'nishuo',age:'haha'},resData:{userid:'heihe'}}";
        final ApiBean apiBean = new Gson().fromJson(jsonStr, ApiBean.class);
        Log.i(Constant.TAG.api, apiBean.getReqData().toString());
        Student student = new Gson().fromJson(apiBean.getReqData().toString(), Student.class);
        Log.i(Constant.TAG.api, new Gson().toJson(student));
        Log.i(Constant.TAG.api, new Gson().toJson(apiBean.getReqData()));


        String strs = "[{'username':'test'},{'username':'test2'}]";
        ArrayList<Student> array = GsonUtil.jsonArrayToList(strs, Student.class);
        for (int i = 0, len = array.size(); i < len; i++) {
            Log.i(Constant.TAG.map, array.get(i).getUsername().toString());
        }
    }
}
